home *** CD-ROM | disk | FTP | other *** search
- Path: news.gate.net!news-adm
- From: Dale Hollon <hollon@gate.net>
- Newsgroups: comp.lang.c
- Subject: Re: Malloc extended memory
- Date: Sun, 31 Mar 1996 13:20:54 -0500
- Organization: CyberGate, Inc.
- Message-ID: <315ECD06.5BE0@gate.net>
- References: <NEWTNews.31774.828246330.Postmaster@pi-user.pi.net>
- NNTP-Posting-Host: tpafl2-29.gate.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- rjvdiest@pi-user.pi.net wrote:
- >
- > I would like a simple C-program that explains to me how to allocate extended
- > memory! Thanks.This will allocate memory for a string inputed by the user.
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- main()
- {
- char temp[80], *string;
-
- printf("\n\nEnter a string.\n\n");
- gets(temp);
- /* malloc will return NULL if unsuccessful */
- string=(char *)malloc(strlen(temp)+1);
- if(string==NULL)
- {
- printf("\n\nCould not allocate memory.\n");
- exit(1);
- }
- strcpy(string,temp);
- printf("\n\n%s\n",string);
-
- return 0;
- }
-